#!/usr/bin/perl
#modify.cgi

require './alarms-lib.pl';
&ReadParse();
&error_setup($text{'error_mesg'});
#&header("123",undef,"index",undef,0);
$hour=$in{'hour'};
$day=$in{'day'};
$month=$in{'month'};
$s=$in{'host_valid'};
#print $s;
$action = 1;
#print "-1";
if($action){
    	$line="0 ".$hour." ".$day." ".$month." * /etc/rc.d/alarms.pl\n";
   	open(FH, "/sysvol/etc/cronfile");
    	@cron_change=<FH>;
    	$cron_num_change=@cron_change;
    	close(FH);
    	unlink("/sysvol/etc/cronfile_tmp");
    	open(FHB, ">>/sysvol/etc/cronfile_tmp");
    	$j=0;
#	print $line;
	for($i=0; $i<$cron_num_change; $i++){
        	if($cron_change[$i] =~ /alarms/){
        		$j=1;     
#			print 0;
			print FHB $line; 
         	}else{# print 1;
             		print FHB $cron_change[$i];
         	}
	}
	if($j==0){# print 2;
		print FHB $line;
	}

    	close(FHB);
    	unlink("/sysvol/etc/cronfile");
    	rename("/sysvol/etc/cronfile_tmp","/sysvol/etc/cronfile");
}
system('crontab /sysvol/etc/cronfile');
system('/etc/init.d/crond restart');
#print $in{'host_valid'};
open(CC,">/sysvol/etc/alarmconf");
print CC "$in{'host_valid'}".":"."hostname=$in{'hostname'}\n";
print CC "$in{'mail_valid'}".":"."mail";
close(CC);
#print "1"."$in{'hostname'}"."1";
#if($in{'mail_valid'}=~/checked/){
open (FH,">/etc/mailconf");
@conf=<FH>;
$conf[0]="smtp".":"."$in{'smtp'}";
$conf[1]="from".":"."$in{'sender'}";
$conf[2]="to".":"."$in{'receiver'}";
$conf[3]="passwd".":"."$in{'passwd'}";
$conf[4]="subject".":"."$text{'nas_alarm'}";
#	$conf[5]=$in{'content'};
foreach(@conf){
	print FH "$_\n";
}
close(FH); 
#}
#print $conf[0];
#&footer("/",$text{'index'});
&redirect("index.cgi");
